Computer software systems can be very complex systems in which the same sequence of instructions may be executed multiple times. For example, a computer program may provide a window area that contains the contents of a bitmap. As the computer program executes, it may enter various states in which contents of different bitmaps should be displayed. Thus, the computer program may repeatedly execute the same sequence of instructions needed to redisplay the contents of a bitmap. A computer program could simply contain a copy of this sequence of instructions in various places throughout the computer program at the point at which the contents of different bitmaps are to be displayed. However, such copies of the same instructions have problems in that computer program memory needs memory to store the copies and a programmer may need to develop and debug each copy separately.
Most programming languages and computer instruction sets support the concept of a function (i.e., subroutine) to help alleviate these problems. A function is a sequence of instructions that can be executed at various times throughout execution of the computer program. However, rather than copying the sequence of instructions at various places throughout the computer program, wherever the sequence instructions should be copied a function invocation instruction is placed instead. The execution of the invocation instruction causes the instructions of the function to be executed, and after completing the execution of those instructions, the instructions after the invocation instruction are executed. The net effect is that the instructions are executed in the same sequence as if they had been copied in place of the invocation instruction. Since the invoking program may want to execute the same sequence of instructions but operate on different data (e.g., different bitmaps), parameters can be passed to functions. For example, in the case of a function that displays a bitmap, one parameter could be the bitmap that is to be displayed. Thus, at various points of the computer program the display bitmap function can be invoked, passing the particular bitmap that is to be displayed at that point during the execution of the computer program.
When a programmer develops functions, the programmer defines the number, types, and order of parameters that are to be passed to the function when invoked. For example, the function to display a bitmap may be passed three parameters: a pointer to the bitmap, an integer indicating the number of columns in the bitmap, and an integer indicating the number of rows in the is bitmap. The definition of the number, type, and order of parameters to be passed to a function is provided by the "prototype" of the function. The following statement is an example prototype for the function to display a bitmap.
DisplayBitmap (bitmap*ptr, int rows, int columns)
The invoking program needs the same number, type, and order of parameters as specified in the prototype. To pass the parameters, the invoking program needs to store the parameters at a location where the invoked function can retrieve the parameters. For example, the parameters may be stored on the top of stack by the invoking program. The function can then use the stack pointer to locate and retrieve the parameters. For this example prototype, the invoking program stores a pointer to the bitmap to be displayed onto the stack, followed by integers indicating the number of rows and columns. Translators (e.g., compilers or interpreters) for a programming language generally use a predefined convention for storing parameters to be passed to a function. For example, one convention is that all parameters are passed via the stack in the same order as they appear in the prototype. The use of a passing convention allows a program compiled by one compiler to invoke a function compiled by another compiler, and the parameters will be correctly passed.
Parameters can be passed either by "value" or by "reference." When a parameter is passed by value, the value of the actual parameter is stored in the stack. (The term "formal" parameter refers to the parameter name that is used in the prototype (e.g., "ptr") and that name is used to reference the parameter in the function. The term "actual" parameter refers to the variable that is actually passed when the function is invoked.) When a parameter is passed by reference, the address of the actual parameter is stored in the stack. The prototype for the DisplayBitmap function indicates that the bitmap is passed by reference and that the number of rows and columns are passed by value. The prototype for a function needs to specify (explicitly or implicitly) whether each parameter is passed by value or reference. In the C++ programming language, an asterisk ("*") appended to the name of a type in the declaration of a parameter indicates that the parameter is a reference to a value of that type, rather than the value of that type. For example, the declaration "bitmap* ptr" indicates that the parameter "ptr" is a reference to a bitmap, whereas the declaration "bitmap bm" would indicate that the parameter "bm" is a bitmap. When a parameter is passed by value, the function cannot modify the actual argument itself Conversely, when a parameter is passed by reference, then the functions can use the address to modify the actual argument itself Thus, parameters are typically passed by value when the function does not modify the parameter and by reference when the function modifies the parameter.
Certain programming languages have been developed which are well suited to implementing software systems in certain application domains. For example, the Java programming language was developed explicitly to support the implementation of computer programs that are hardware independent. The Java programming language also defines a set of primitive data types (e.g., integers), object data types, and a convention for passing parameters. In particular, all parameters that have a primitive type are passed by value and that are objects are passed by reference. Although virtually any computer program can be developed using the Java programming language, it may be easier to develop certain portions of the computer program using another programming language (e.g., the C++ programming language). In general, it may be desirable to intermix the programming languages used to develop a computer program for several reasons. First, it may be more efficient to implement a portion of the computer program using one programming language rather than another. Second, it may be that various functions have already been implemented in one programming language, and it would be costly to reimplement the function in another programming language. However, the programming languages may not support the same primitive data types and thus, the types of the parameters may not be fully compatible. For example, a date type in one programming language may be defined in a MM/DD/YY format, while the date type in another programming language may be defined in a YY/MM/DD format.
Some programming language translators have been developed to map the data types of one programming language to the data types of another programming language when a function implemented in one programming language is invoked by a computer program implemented in another programming language. The converting and passing of a parameter is referred to as "marshaling" the parameter. For example, the translator may detect that a function developed in another programming language is to be invoked and that the date types are not compatible. The translator may convert the date parameter to the format expected by the function before invoking the function and convert the date parameter to the format expected by the invoking program upon return from the function. However, the translator can only convert between types for which it happens to have predefined marshaling code. If a programmer defines a complex data type, then the translator is unlikely to be able to perform the needed conversions automatically.